﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Sample.Novel.Domain.Books.Entites;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.EntityFrameworkCore.Modeling;

namespace Sample.Novel.EntityFrameworkCore.Mappings
{
    internal class ChapterMap
        :IEntityTypeConfiguration<Chapter>
    {
        public void Configure(EntityTypeBuilder<Chapter> builder)
        {
            builder.ToTable(nameof(Chapter)); ;
            builder.HasIndex("Id", "Title");
            builder.HasKey("Id");
            builder.ConfigureByConvention();
            builder.Property(chapter => chapter.Title)
                .IsRequired()
                .HasMaxLength(500);
            builder.HasOne(chapter => chapter.ChapterText)
                .WithOne(text => text.Chapter)
                .HasForeignKey<ChapterText>(text => text.Id);
            
        }
    }
}
